package com.example.demo.web;

import com.example.demo.domian.Role;
import com.example.demo.repository.RoleRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/role")
@Api(value = "角色相关接口",description = "角色相关接口")
public class RoleController {

    @Autowired
    RoleRepository roleRepository;

    @GetMapping("/")
    @ApiOperation("获取全部角色")
    public Object findAll(){
        return roleRepository.findAll();
    }

    @GetMapping("/{id}")
    @ApiOperation("获取单个角色信息")
    public Object findOne(@PathVariable String id){
        return roleRepository.findOne(id);
    }

    @PostMapping("/save")
    @ApiOperation("保存/更新 角色信息")
    public Object save(@RequestBody Role role){
        return roleRepository.save(role);
    }

    @DeleteMapping("/{id}/del")
    @ApiOperation("删除单个角色")
    public Object del(@PathVariable String id){
        roleRepository.delete(id);
        return true;
    }
}
